#include "Isle.h"

Isle::Isle(GameState *gameState, float size) : PhysicalObject(gameState){
	addProperty("Isle");
	addProperty("oneway");
	addProperty("ground");
	addProperty("stepdown");
	setLayer(4);
	m_texture = gameState->getTextureManager().getTexture("isle1.png");

	setSize(b2Vec2(size, size * (float(m_texture->getSize().y)/m_texture->getSize().x)));
	

	getBodyDef()->type = b2_kinematicBody;
	getBodyDef()->fixedRotation = true;
	b2FixtureDef *fixDef = new b2FixtureDef;
	fixDef->filter.groupIndex = -2;
	b2PolygonShape *shape = new b2PolygonShape;
	shape->SetAsBox(size/2,size/16, b2Vec2(0.0f,-size/16),0);
	fixDef->shape = shape;
	fixDef->density = 2.0f;
	fixDef->friction = 1.0f;
	fixDef->restitution = 0.0f;
	addFixtureDef(fixDef);
	setRotation(0.0f);

	m_time = 0;

	
	
}




void Isle::update(double dt){
	m_time+=dt;
	

	//b2Vec2 targetPos(getPosition().x, m_initYPos+cos(m_time+m_initTime));
	//m_body->SetLinearVelocity((targetPos-getPosition()));
}


void Isle::draw(){

	//drawFixtures();

	b2Vec2 pos = getPosition();

	sf::Texture::bind(m_texture);

	glPushMatrix();
	{
		glTranslatef(pos.x, pos.y-0.25f*m_size.x, 0.0f); 
		glScalef(getSize().x, getSize().y, 1);
		glBegin(GL_QUADS);
		{
			glTexCoord2f(0.0f, 1.0f); glVertex3f( -0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, -0.5f, -0.2f);
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 0.5f, -0.2f);
			glTexCoord2f(0.0f, 0.0f); glVertex3f( -0.5f, 0.5f, -0.2f);
		}
		glEnd();
	}
	glPopMatrix();

	sf::Texture::bind(NULL);
}


